home *** CD-ROM | disk | FTP | other *** search
/ Amiga Tools 1 / Amiga Tools.iso / egs-tools / egs_dev-disk / egsdemos / moreexamples / boolean / boolean.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-06-06  |  9.4 KB  |  224 lines

  1.                         /*    Boolean.c
  2.                            This code demonstrates Boolean gadgets.
  3.  
  4.                            Patrick Hager, Great Valley Products Inc.
  5.                            November 2, 1993
  6.                         */
  7.  
  8.  
  9. #include <stdio.h>
  10. #include "/global/userwindow.h"
  11. #include "/global/egslibraries.h"
  12.  
  13. #include <egs/egsintui.h>
  14. #include <egs/clib/egsintui_protos.h>
  15. #include <egs/pragmas/egsintui_pragmas.h>
  16. #include <egs/egsgadbox.h>
  17. #include <egs/clib/egsgadbox_protos.h>
  18. #include <egs/pragmas/egsgadbox_pragmas.h>
  19.  
  20.  
  21.  
  22.  
  23. #define SIMPLE_ID  100          // Gadget ID base for three Simple Booleans.
  24.  
  25.  
  26.                                 /* Used with Simple Mode.
  27.                                    If (Simple_Mode & LEFT_SIMPLE_FLAG) it means this
  28.                                    button is pushed in. This is just my way of
  29.                                    doing it. You must remember your button
  30.                                    positions somehow, so you can correctly
  31.                                    redraw them on a reopen, or a resize.
  32.                                 */
  33. #define LEFT_SIMPLE_FLAG   1
  34. #define MIDDLE_SIMPLE_FLAG 2
  35. #define RIGHT_SIMPLE_FLAG  4
  36.  
  37. #define EXCLUDE_ID 200       // Gadget ID Base for 5 Mutually Excluded Booleans.
  38. #define NUM_EXCLUDE_GADGETS 5   // Number of Mutually Excluded Gadgets (5)
  39.  
  40.  
  41.                                 // Our UserInputWindow structure.
  42. struct UserInputWindow Example_Request;
  43.  
  44.                                 // This is necessary to have mutually excluded
  45.                                 // boolean gadgets. Allocate to one more than
  46.                                 // the number of gadgets, and fill last one
  47.                                 // with NULL.
  48. EI_BoolGadPtr Exclude_List[NUM_EXCLUDE_GADGETS+1];
  49.  
  50.                                 // Shows me which Mutually Excludeded Boolean is
  51.                                 // is pressed in. (0-4)
  52. WORD Mutual_Mode=0;
  53. UWORD Simple_Mode=0;            // See above. LEFT_SIMPLE_FLAG etc.
  54.  
  55.  
  56.  
  57.            // Local PRIVATE function Prototypes.
  58.  
  59. EB_GadBoxPtr Create_Example (UserInputWindowPtr UserWindow);
  60. void GadgetDown_Example (UserInputWindowPtr UserWindow, EI_GadgetPtr iaddress);
  61. void Redraw_Example (UserInputWindowPtr UserWindow);
  62.  
  63.  
  64. /****************************
  65.       MAIN CODE
  66. ****************************/
  67. void main (void) {
  68.  
  69.   if (OpenEGSLibraries ()) {
  70.     Init_UserWindow (&Example_Request, "Boolean Example Window",WINDOW_MODAL,
  71.                      NULL,NULL);
  72.     Example_Request.Create     = Create_Example;
  73.     Example_Request.GadgetDown = GadgetDown_Example;
  74.     Example_Request.Redraw     = Redraw_Example;     // We need redraw to update
  75.                                                      // on resize or reopen.
  76.     Example_Request.IDCMPFlags = EI_iCLOSEWINDOW | EI_iSIZEVERIFY |
  77.                                  EI_iNEWSIZE | EI_iGADGETDOWN;
  78.     Example_Request.Flags =      EI_SIZEBBOTTOM| EI_SIMPLE_REFRESH |
  79.                                  EI_GIMMEZEROZERO;
  80.     Example_Request.SysGadgets = (EI_WINDOWCLOSE)|(EI_WINDOWSIZE)|EI_WINDOWDRAG|
  81.                                  EI_WINDOWFRONT|EI_WINDOWBACK;
  82.  
  83.     if (Open_UserWindow (&Example_Request,-1,-1)) {
  84.       Close_UserWindow (&Example_Request);
  85.     }
  86.     else
  87.       printf ("Couldn't open my window!\n");
  88.  
  89.   }
  90.   CloseEGSLibraries ();  // after the bracket cause what if I opened 3 but
  91.                          // couldn't find the rest, still need to close the 3.
  92. }
  93.  
  94. /*************************************
  95.    PRIVATE:  Create_Example.
  96.              This routine is called by the UserWindow routines.
  97.              It passes back a GadBoxPtr to the gadgets wanted.
  98. *************************************/
  99. EB_GadBoxPtr Create_Example (UserInputWindowPtr UserWindow) {
  100.   EB_GadBoxPtr root, horiz, box;
  101.   EB_GadContext gadcon;
  102.  
  103.   gadcon = UserWindow->GadCon;
  104.  
  105.   root = EB_CreateVertiBox (gadcon);
  106.   EB_AddLastSon (root,EB_CreateVertiFill (gadcon,0,0));
  107.   EB_AddLastSon (root,EB_CreateCenterText (gadcon,"Note we remember positions "
  108.                                                   "on resize..."));
  109.  
  110.                 /*  For the Simple Booleans along the top, I just check the
  111.                     Simple_Mode variable as I create the gadgets. If this
  112.                     particular gadget needs to be pressed in, set the Flag
  113.                     to one. You can look up these structures in egsgadbox.h.
  114.                 */
  115.   EB_AddLastSon (root,EB_CreateVertiFill (gadcon,0,0));
  116.     horiz=EB_CreateHorizBox (gadcon);
  117.     box=EB_CreateTextBoolean (gadcon,"Simple Boolean 1",SIMPLE_ID+0,EB_FILL_ALL);
  118.     if (Simple_Mode & LEFT_SIMPLE_FLAG)
  119.       ((EI_BoolGadPtr)box->Render.Gad)->Flag=1;
  120.     EB_AddLastSon (horiz,box);
  121.     box=EB_CreateTextBoolean (gadcon,"Simple Boolean 2",SIMPLE_ID+1,EB_FILL_ALL);
  122.     if (Simple_Mode & MIDDLE_SIMPLE_FLAG)
  123.       ((EI_BoolGadPtr)box->Render.Gad)->Flag=1;
  124.     EB_AddLastSon (horiz,box);
  125.     box=EB_CreateTextBoolean (gadcon,"Simple Boolean 3",SIMPLE_ID+2,EB_FILL_ALL);
  126.     if (Simple_Mode & RIGHT_SIMPLE_FLAG)
  127.       ((EI_BoolGadPtr)box->Render.Gad)->Flag=1;
  128.     EB_AddLastSon (horiz,box);
  129.   EB_AddLastSon (root,horiz);
  130.  
  131.                  /*  For the Five Mutually Excluded Gadgets along the bottom,
  132.                      I need to do a couple things.
  133.                      First. UnSet the EI_TOGGLE_SELECT Flag. This keeps the
  134.                             gadget from being toggled from one state to another.
  135.                             if its pushed in, you can't push it out.
  136.                      Second. Set its Exclude struct to our List we allocated at
  137.                              runtime. This tells EGS which ones to pop out if
  138.                              this gadget is pressed in.
  139.                      Third. Add to the list with this gadget. (The list wouldn't
  140.                             do EGS much good unless it contained the gadget's
  141.                             addresses.) Set the Last Entry to NULL.
  142.                  */
  143.     horiz=EB_CreateHorizBox (gadcon);
  144.       box=EB_CreateTextBoolean (gadcon,"Exclude Boolean 1",EXCLUDE_ID+0,EB_FILL_ALL);
  145.       ((EI_BoolGadPtr)box->Render.Gad)->Class.Flags &= (~EI_TOGGLE_SELECT);
  146.       ((EI_BoolGadPtr)box->Render.Gad)->Exclude=(struct EI_BoolGadget **) &Exclude_List;
  147.       Exclude_List[0]=(EI_BoolGadPtr)box->Render.Gad;
  148.     EB_AddLastSon (horiz,box);
  149.       box=EB_CreateTextBoolean (gadcon,"Exclude Boolean 2",EXCLUDE_ID+1,EB_FILL_ALL);
  150.       ((EI_BoolGadPtr)box->Render.Gad)->Class.Flags &= (~EI_TOGGLE_SELECT);
  151.       ((EI_BoolGadPtr)box->Render.Gad)->Exclude=(struct EI_BoolGadget **) &Exclude_List;
  152.       Exclude_List[1]=(EI_BoolGadPtr)box->Render.Gad;
  153.     EB_AddLastSon (horiz,box);
  154.       box=EB_CreateTextBoolean (gadcon,"Exclude Boolean 3",EXCLUDE_ID+2,EB_FILL_ALL);
  155.       ((EI_BoolGadPtr)box->Render.Gad)->Class.Flags &= (~EI_TOGGLE_SELECT);
  156.       ((EI_BoolGadPtr)box->Render.Gad)->Exclude=(struct EI_BoolGadget **) &Exclude_List;
  157.       Exclude_List[2]=(EI_BoolGadPtr)box->Render.Gad;
  158.     EB_AddLastSon (horiz,box);
  159.       box=EB_CreateTextBoolean (gadcon,"Exclude Boolean 4",EXCLUDE_ID+3,EB_FILL_ALL);
  160.       ((EI_BoolGadPtr)box->Render.Gad)->Class.Flags &= (~EI_TOGGLE_SELECT);
  161.       ((EI_BoolGadPtr)box->Render.Gad)->Exclude=(struct EI_BoolGadget **) &Exclude_List;
  162.       Exclude_List[3]=(EI_BoolGadPtr)box->Render.Gad;
  163.     EB_AddLastSon (horiz,box);
  164.       box=EB_CreateTextBoolean (gadcon,"Exclude Boolean 5",EXCLUDE_ID+4,EB_FILL_ALL);
  165.       ((EI_BoolGadPtr)box->Render.Gad)->Class.Flags &= (~EI_TOGGLE_SELECT);
  166.       ((EI_BoolGadPtr)box->Render.Gad)->Exclude=(struct EI_BoolGadget **) &Exclude_List;
  167.       Exclude_List[4]=(EI_BoolGadPtr)box->Render.Gad;
  168.       Exclude_List[5]= NULL;
  169.     EB_AddLastSon (horiz,box);
  170.   EB_AddLastSon (root,horiz);
  171.  
  172.   return root;
  173. }
  174.  
  175. /**************************************
  176.     PRIVATE:  GadgetDown_Example.
  177.               This routine handles the gadget down events passed to the
  178.               Example Control Window.
  179. **************************************/
  180. void GadgetDown_Example (UserInputWindowPtr UserWindow, EI_GadgetPtr iaddress) {
  181.  
  182.          // Process our mutually Excluded Bool Gadgets.
  183.  
  184.   if ((iaddress->GadgetID >= EXCLUDE_ID)&&
  185.       (iaddress->GadgetID < EXCLUDE_ID+NUM_EXCLUDE_GADGETS)) {
  186.          // Sets our mode to 0-4.
  187.     Mutual_Mode = iaddress->GadgetID-EXCLUDE_ID;
  188.   }
  189.   else switch (iaddress->GadgetID) {
  190.  
  191.          //If it was pushed in,... pop it out and vice versa
  192.          // (^ = Exclusive Or.)
  193.     case SIMPLE_ID:   Simple_Mode ^= LEFT_SIMPLE_FLAG;   break;
  194.     case SIMPLE_ID+1: Simple_Mode ^= MIDDLE_SIMPLE_FLAG; break;
  195.     case SIMPLE_ID+2: Simple_Mode ^= RIGHT_SIMPLE_FLAG;  break;
  196.   }
  197. }
  198.  
  199. /**************************************
  200.     PUBLIC:  Redraw_Example.
  201.              This routine handles redraw events to the Example
  202.              Control Window. Called by UserWindow routines, and
  203.              could be called by other routines as well.
  204.              Also called on an EI_iREFRESHWINDOW message.
  205. **************************************/
  206. void Redraw_Example (UserInputWindowPtr UserWindow) {
  207.   int i;
  208.  
  209.             /* Assume we are starting out with a fresh set of gadgets,
  210.                (from a resize, or a reopen), and set the appropriate
  211.                Mutual Boolean gadget's flag to True.
  212.                Then refresh all of the mutual exclude gadgets.
  213.             */
  214.  
  215.   Exclude_List[Mutual_Mode]->Flag=TRUE;
  216.   for (i=0;i<NUM_EXCLUDE_GADGETS;i++) {
  217.     EI_RefreshGadget (UserWindow->Window,(EI_GadgetPtr)Exclude_List[i]);
  218.   }
  219.  
  220.           /*  There is no need to refresh the Simple gadgets along the top,
  221.               because they were set accordingly in the Create routine.
  222.           */
  223. }
  224.